package com.fitns.user.controller.user;

import com.fitns.user.conf.Resp;
import com.fitns.user.conf.ZhhwResp;
import com.fitns.user.dto.user.RoleCondition;
import com.fitns.user.dto.user.RoleVO;
import com.fitns.user.dto.user.UserVO;
import com.fitns.user.model.user.Privilege;
import com.fitns.user.model.user.Role;
import com.fitns.user.service.user.PrivilegeService;
import com.fitns.user.service.user.RoleService;
import com.fitns.user.utils.ResultData;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/role")
@RestController
@Api(description = "角色管理")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/search")
    @ApiOperation("查询（包含模糊查询")
    public Object search(RoleCondition  roleCondition){
        PageInfo<RoleVO> roleVOS= roleService.search(roleCondition);
        roleVOS.setPageSize(roleCondition.getPageSize());
        return Resp.page(roleVOS);
    }

    @PostMapping("/add")
    @ApiOperation(("新增角色"))
    public ZhhwResp add(@RequestBody RoleVO roleVO){
        Role role= roleService.insert(roleVO);
        return ZhhwResp.createSuccess(role);
    }

    @GetMapping("/roleMembers")
    @ApiOperation("成员管理")
    public Object roleMembers(RoleCondition roleVO){
        PageInfo<UserVO> userVOPageInfo= roleService.searchByRole(roleVO);
        userVOPageInfo.setPageSize(roleVO.getPageSize());
        return Resp.page(userVOPageInfo);
    }

    @PutMapping("/modify")
    @ApiOperation("修改")
    public ResultData modify(@RequestBody RoleVO roleVO){
        RoleVO roleVO1=roleService.modify(roleVO);
        return new ResultData(200,"SUCESS",roleVO1,"");
    }

    @DeleteMapping
    @ApiOperation(("删除"))
    public ResultData delete(@RequestBody RoleVO roleVO){
        roleService.delete(roleVO);
        return new ResultData(200,"SUCESS",null,"");
    }

    @GetMapping("/gerUserRole")
    @ApiOperation("获取登录用户拥有的角色")
    public ResultData gerUserRole(){
        List<RoleVO> roleVOS= roleService.searchByCreateId();
        return new ResultData(200,"SUCESS",roleVOS,"");
    }




}
